package com.ohuang.xposed_tiktok.tiktok;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;


import com.ohuang.xposed_tiktok.SPUtil;
import com.ohuang.xposed_tiktok.smallwindow.FloatViewManager;
import com.ohuang.xposed_tiktok.smallwindow.WindowInterface;

/**
 * 用于tiktok逆向
 */
public class IsoManager {
    public static final String TAG = "TikTokHook";

    public static String countryIso="";


    public static String getCountryIso() {
        return countryIso;
    }

    static boolean isinit=false;

    public static void init(Application application) {
        if (isinit) {
            return;
        }
        isinit=true;
        countryIso = (String) SPUtil.getInstance("tiktokHook").get(application, "iso", "jp");
        FloatViewManager.getInstance().text="切换地区";
        FloatViewManager.getInstance().setWindowUiFactory(new FloatViewManager.WindowUiFactory() {
            @Override
            public WindowInterface create(Activity activity) {
                return new CoutryIsoWindowUI(activity);
            }
        });
        application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                FloatViewManager.getInstance().attach(activity);
            }

            @Override
            public void onActivityStarted(Activity activity) {

            }

            @Override
            public void onActivityResumed(Activity activity) {
                FloatViewManager.getInstance().show(activity);
            }

            @Override
            public void onActivityPaused(Activity activity) {
                FloatViewManager.getInstance().hide(activity);
            }

            @Override
            public void onActivityStopped(Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(Activity activity) {
                FloatViewManager.getInstance().onDestroy(activity);
            }
        });

    }
}
